﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="MattersResponses", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(MattersResponses))]
    public class MattersResponsesSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMattersResponses clazz;
        
        public MattersResponsesSerializer(IMattersResponses clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (((clazz.MattersResponse == null) 
                        || (clazz.MattersResponse.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "MattersResponse");
            }
            for (int x = 0; ((clazz.MattersResponse != null) 
                        && (x < clazz.MattersResponse.Count)); x = (x + 1)) {
                Writer.WriteStartElement("MattersResponse");
                if (clazz.MattersResponse[x]!=null) {
                    global::Xtee.Core.SerializationMetadata metaMattersResponse = this.GetMetaData(clazz.MattersResponse[x]);
                    Writer.WriteTypeAttribute(metaMattersResponse.TypeQualifiedName.Namespace, metaMattersResponse.TypeQualifiedName.Name);
                    metaMattersResponse.NewSerializer(clazz.MattersResponse[x]).WriteXml(Writer);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : MattersResponse");
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            clazz.MattersResponse = new System.Collections.Generic.List<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMattersResponse>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "MattersResponse")); ) {
                if (Reader.LocalName=="MattersResponse") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MattersResponses>MattersResponse");
                    }
                    global::Xtee.Core.SerializationMetadata metaMattersResponse = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMattersResponse>(Reader, "MattersResponse", "http://producers.kis.xtee.riik.ee/producer/kis");
                    global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMattersResponse item = metaMattersResponse.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMattersResponse>();
                    clazz.MattersResponse.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("MattersResponse");
                        metaMattersResponse.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MattersResponses>MattersResponse", Reader.LocalName);
                }
            }
            if ((clazz.MattersResponse.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "MattersResponse");
            }
        }
    }
}
